#include "alttiledmap.h"

#include <QPainter>
#include <QStyleOptionGraphicsItem>

namespace Alt {
     QDataStream& operator << (QDataStream& stream, const Tile& tile) {
          return stream << tile.material << tile.tileNumber;
     }

     QDataStream& operator >> (QDataStream& stream, Tile& tile) {
          return stream >> tile.material >> tile.tileNumber;
     }

     TiledMap::TiledMap(QGraphicsItem* parent) : Map (parent) {
          setTileset(Tileset(QImage("/home/herenbdy/Pictures/sheet0.png"), QSize(48, 48), QPoint(2, 2)));
     }

     QRectF TiledMap::boundingRect() const {
          return m_tileset.image().rect();
     }

     bool TiledMap::load(QDataStream& stream) {
          stream >> m_tileset >> m_tiles;
          return true;
     }

     QString TiledMap::mapType() const {
          return "alt tiled map";
     }

     int TiledMap::material(const QPointF& pos) const {
          Q_UNUSED(pos);
          return -1;
     }

     void TiledMap::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
          Q_UNUSED(painter);
          Q_UNUSED(option);
          Q_UNUSED(widget);
          return;
     }

     Projection TiledMap::projection() const {
          return ThreeFourthsTopDown;
     }

     bool TiledMap::save(QDataStream& stream) const {
          stream << mapType() << m_tileset << m_tiles;
          return true;
     }

     void TiledMap::setTileset(const Tileset& tileset) {
          m_tileset = tileset;
          return;
     }

     int TiledMap::type() const {
          return UserType + 100;
     }

     const Tileset& TiledMap::tileset() const {
          return m_tileset;
     }

     //private
}

